﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.IDAL;
using KPIS.GERP.GFMS.DALFactory;

// test only
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.BLL
{
    public class B_FIM_MoneyRequestDtlsRates : IBLL_FIM_MoneyRequestDtlsRates
    {
        Common common = new Common();
        private static readonly IDAL_FIM_MoneyRequestDtlsRates dal = DataAccess.Create_FIM_MoneyRequestDtlsRates();

        public B_FIM_MoneyRequestDtlsRates()
        {

        }

        public IList<M_FIM_MoneyRequestDtlsRates> GetFull(string money_req_dtls_seq, string exp_rate_seq)
        {
            Nullable<int> nmoney_req_dtls_seq = common.ConvertNullInt(money_req_dtls_seq);
            Nullable<int> nexp_rate_seq = common.ConvertNullInt(exp_rate_seq);
            //Nullable<int>[] nexp_rate_type_seq;
            //int j = 0;

            //if (exp_rate_type_seq != null)
            //{
            //    for (int i = 0; i < exp_rate_type_seq.Length; i++)
            //    {
            //        if (exp_rate_type_seq[i] != null)
            //        {
            //            if (exp_rate_type_seq[i].Length > 0)
            //            {
            //                j++;
            //            }
            //        }
            //    }

            //    nexp_rate_type_seq = new int?[j];

            //    for (int i = 0; i < j; i++)
            //    {
            //        nexp_rate_type_seq[i] = common.ConvertNullInt(exp_rate_type_seq[i]);
            //    }
            //}
            //else
            //{
            //    nexp_rate_type_seq = new int?[0];
            //}

            return dal.GetFull(nmoney_req_dtls_seq, nexp_rate_seq);
        }

        public IList<M_FIM_MoneyRequestDtlsRates> GetFull2(string bgm_proj_oper_exp_seq, string exp_rate_seq)
        {
            Nullable<int> nbgm_proj_oper_exp_seq = common.ConvertNullInt(bgm_proj_oper_exp_seq);
            Nullable<int> nexp_rate_seq = common.ConvertNullInt(exp_rate_seq);
            //Nullable<int>[] nexp_rate_type_seq;
            //int j = 0;

            //if (exp_rate_type_seq != null)
            //{
            //    for (int i = 0; i < exp_rate_type_seq.Length; i++)
            //    {
            //        if (exp_rate_type_seq[i] != null)
            //        {
            //            if (exp_rate_type_seq[i].Length > 0)
            //            {
            //                j++;
            //            }
            //        }
            //    }

            //    nexp_rate_type_seq = new int?[j];

            //    for (int i = 0; i < j; i++)
            //    {
            //        nexp_rate_type_seq[i] = common.ConvertNullInt(exp_rate_type_seq[i]);
            //    }
            //}
            //else
            //{
            //    nexp_rate_type_seq = new int?[0];
            //}

            return dal.GetFull2(nbgm_proj_oper_exp_seq, nexp_rate_seq);
        }

        public M_FIM_MoneyRequestDtlsRates GetInfo(string seq)
        {
            int nSeq;

            if (seq == null)
                return null;

            if (common.IsNumeric(seq))
            {
                nSeq = int.Parse(seq);
                return dal.GetInfo(nSeq);
            }
            else
            {
                return null;
            }
        }

        public M_FIM_MoneyRequestDtlsRates GetInfo(string money_req_dtls_seq, string emp_seq)
        {
            int nmoney_req_dtls_seq;
            int nemp_seq;

            if (money_req_dtls_seq == null || emp_seq == null)
                return null;

            if (common.IsNumeric(money_req_dtls_seq) && common.IsNumeric(emp_seq))
            {
                nmoney_req_dtls_seq = int.Parse(money_req_dtls_seq);
                nemp_seq = int.Parse(emp_seq);
                return dal.GetInfo(nmoney_req_dtls_seq, nemp_seq);
            }
            else
            {
                return null;
            }
        }

        //public string SelectRecentInsertedRoleSeq()
        //{
        //    return dal.SelectRecentInsertedRoleSeq();
        //}

        public string Insert(M_FIM_MoneyRequestDtlsRates info)
        {
            try
            {
                return dal.Insert(info);
            }
            catch
            {
                throw;
            }
        }

        public void Update(M_FIM_MoneyRequestDtlsRates info)
        {
            try
            {
                dal.Update(info);
            }
            catch
            {
                throw;
            }
        }

        public void Delete(M_FIM_MoneyRequestDtlsRates info)
        {
            try
            {
                dal.Delete(info);
            }
            catch
            {
                throw;
            }
        }
    }
}
